#pragma once
#include "connection.hpp"
#include "reactor.hpp"

class slaver{
public:
    void init(){
        _r.Init();
    }
    void start(){
        _r.insert(_listensock);
        _r.setlistenfd(_listensock->GetFd());
        _r.insert(_r_pipe);
        _r.Loop();
    }
    void set_read_pipe(connect_t r_pipe){ 
        r_pipe->setevent(EPOLLIN);
        _r_pipe=r_pipe;
    }
    void set_listensock(connect_t listensock){
        _listensock=listensock;
        //这个子进程的listensocket不需要监视任何事件
        _listensock->setevent(0);
        _listenfd=_listensock->GetFd();
    }
    int getlistenfd() {return _listenfd;}
private:
    connect_t _listensock;
    connect_t _r_pipe;//管道读端
    int _listenfd;
    reactor _r;
};